from django.shortcuts import render
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response

from apis.models import PeopleInfo
from apis.serializers import PeopleInfoSerializer


# Create your views here.
@api_view(['GET', 'POST'])
def manage_info(request):
    if request.method == 'GET':
        qs = PeopleInfo.objects.all()
        serializer = PeopleInfoSerializer(instance=qs, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
    else:
        serializer = PeopleInfoSerializer(request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_200_OK)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
